package com.kjcxlab.avcviewer.util;

/**
 * Created by Xianlee on 8/7/2015.
 */
public class Constants {
    public static final String DEBUG_TAG = "PushToTalk";

    /* Video parmeters */
    public final static String VIDEO_TYPE_AVC = "video/avc";
    public final static int VIDEO_WDITH = 640;
    public final static int VIDEO_HEIGHT = 480;
    public final static String ADDRESS = "224.0.0.8";
    public final static int LOCAL_PORT = 6050;
    public final static byte SPS_HEADER = 7;
    public final static byte PPS_HEADER = 8;

    /* some parameters about rtp protocol */
    public final static int RTP_PACKAGE_SINGEL = 23; // 1-23: single nal
    public final static int RTP_PACKAGE_FU_A = 28; // 28: FU-A package
    public final static int RTP_HEADER_LENGTH = 12;
    public final static int RTP_FU_A_HEADER_LENGTH = 13;
    public final static int RTP_AU_HEADER_LENGTH = 4;
    public final static byte FIRST_FU_A_PACKAGE = 1;
    public final static byte MIDLLE_FU_A_PACKAGE = 0;
    public final static byte LAST_FU_A_PACKAGE = 2;
    public final static String AUDIO_MIME = "audio/m4a-latm";
    public final static String VIDEO_TAG = "Video";
    public final static String AUDIO_TAG = "Audio";
    // *********************** Common Funtions ***********************

    //NOTE:sps-pps of Sintel.h264
    public final static byte[] DEF_SPS = {0x67, 0x64, 0x00, 0x1e, (byte) 0xac, (byte) 0xd9, 0x40, (byte) 0xa0, 0x3d, (byte) 0xbf, (byte) 0xf0, 0x01, (byte) 0xe0, 0x01, 0x11, 0x00
            , 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x30, 0x0f, 0x16, 0x2d, (byte) 0x96};
    public final static byte[] DEF_PPS = {0x00, 0x00, 0x00, 0x01, 0x68, (byte) 0xeb, (byte) 0xe3, (byte) 0xcb, 0x22, (byte) 0xc0};


    /** Gets int value */
    public final static int getInt(byte b) {
        return ((int) b + 256) % 256;
    }

    /** Gets long value */
    public final static long getLong(byte[] data, int begin, int end) {
        long n = 0;
        for (; begin < end; begin++) {
            n <<= 8;
            n += data[begin] & 0xFF;
        }
        return n;
    }

    /** Sets long value */
    public final static void setLong(long n, byte[] data, int begin, int end) {
        for (end--; end >= begin; end--) {
            data[end] = (byte) (n % 256);
            n >>= 8;
        }
    }

    /** Gets Int value */
    public final static int getInt(byte[] data, int begin, int end) {
        return (int) getLong(data, begin, end);
    }

    /** Sets Int value */
    public final static void setInt(int n, byte[] data, int begin, int end) {
        setLong(n, data, begin, end);
    }

    /** Gets bit value */
    public final static boolean getBit(byte b, int bit) {
        return (b >> bit) == 1;
    }

    /** Sets bit value */
    public final static byte setBit(boolean value, byte b, int bit) {
        if (value)
            return (byte) (b | (1 << bit));
        else
            return (byte) ((b | (1 << bit)) ^ (1 << bit));
    }
}
